package cn.wyf.androidcode.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import net.wyf.library.utils.log.XLogger;

import java.util.List;

import cn.wyf.androidcode.R;

/**
 * Created by Wyf on 2017/8/16.
 */

public class DialogGridAdapter extends BaseAdapter {

    private List<String> strs;
    private List<Boolean> isChecked;
    private Context mContext;
    private LayoutInflater inflater;

    public DialogGridAdapter(Context context, List<String> strs,List<Boolean> isChecked) {
        this.mContext = context;
        this.strs = strs;
        this.isChecked = isChecked;
        XLogger.v(strs.toString());
        inflater = LayoutInflater.from(mContext);
    }

    @Override
    public int getCount() {
        return strs != null ? strs.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return strs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View view = inflater.inflate(R.layout.item, null, false);
        RadioButton radioButton = (RadioButton) view.findViewById(R.id.radioId);
        TextView textView = (TextView) view.findViewById(R.id.itemshow);
        textView.setText(strs.get(position));
        radioButton.setChecked(isChecked.get(position));
        return view;
    }

}
